﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Data.OleDb;

namespace MobileManager
{
    public partial class WebTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            #region

            string sXmlMessage = "<up><info><phone id=\"201161905015903\" imei=\"\" "
            + "imsi=\"9460004042627887\" area=\"0230\" mno=\"1\"></phone>"
            + "<gtsbox origin=\"901\" device=\"ABCDEF35B\" compile=\"Oct 25 2011\">"
            + "<version major=\"5\" minor=\"3\" reserved=\"0\"></version></gtsbox>"
            + "<xlite><version major=\"1\" minor=\"0\" reserved=\"1169564127\"></version></xlite></info></up>";

            string DsmpUrl = Request.Url.ToString().Replace("WebTest.aspx", "") + "charge3.aspx";

            //string DsmpUrl = "http://59.151.27.28:8080/charge3.aspx";

            //把sXmlMessage发送到指定的DsmpUrl地址上     
            Encoding encode = System.Text.Encoding.GetEncoding("gbk");
            byte[] arrB = encode.GetBytes(sXmlMessage);
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(DsmpUrl);
            myReq.Method = "POST";
            myReq.ContentType = "text/xml";
            myReq.ContentLength = arrB.Length;
            Stream outStream = myReq.GetRequestStream();
            outStream.Write(arrB, 0, arrB.Length);
            outStream.Close();


            //接收HTTP做出的响应
            WebResponse myResp = myReq.GetResponse();
            Stream ReceiveStream = myResp.GetResponseStream();
            StreamReader readStream = new StreamReader(ReceiveStream, encode);
            Char[] read = new Char[256];
            int count = readStream.Read(read, 0, 256);
            string str = null;
            while (count > 0)
            {
                str += new String(read, 0, count);
                count = readStream.Read(read, 0, 256);
            }
            readStream.Close();
            myResp.Close();

            Response.Write(str);

            #endregion
        }
    }
}
